package com.xdog.okx.config;

import com.xdog.system.service.ISysConfigService;
import jakarta.annotation.Resource;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * OKX API配置类
 */
@Component
@ConfigurationProperties(prefix = "okx.api")
@Slf4j
public class OkxConfig {

    /**
     * API域名
     * -- GETTER --
     *  获取Base URL
     *
     * @return Base URL

     */
    @Setter
    @Getter
    private String baseUrl = "https://www.okx.com";

    /**
     * 连接超时时间(毫秒)
     */
    @Getter
    @Setter
    private int connectTimeout = 30000;

    /**
     * 读取超时时间(毫秒)
     */
    @Setter
    @Getter
    private int readTimeout = 30000;

    /**
     * 代理主机
     */
    @Setter
    @Getter
    private String proxyHost;

    /**
     * 代理端口
     */
    @Setter
    @Getter
    private Integer proxyPort;

    @Resource
    private ISysConfigService sysConfigService;

    /**
     * 获取API Key
     * @return API Key
     */
    public String getApiKey() {
        return sysConfigService.selectConfigByKey("okx.api.key");
    }

    /**
     * 获取Secret Key
     * @return Secret Key
     */
    public String getSecretKey() {
        return sysConfigService.selectConfigByKey("okx.api.secret");
    }

    /**
     * 获取Passphrase
     * @return Passphrase
     */
    public String getPassphrase() {
        return sysConfigService.selectConfigByKey("okx.api.passphrase");
    }

    public String getProxyHost() {
        log.debug("获取代理主机: {}", proxyHost);
        return proxyHost;
    }

    public void setProxyHost(String proxyHost) {
        log.debug("设置代理主机: {}", proxyHost);
        this.proxyHost = proxyHost;
    }

    public Integer getProxyPort() {
        log.debug("获取代理端口: {}", proxyPort);
        return proxyPort;
    }

    public void setProxyPort(Integer proxyPort) {
        log.debug("设置代理端口: {}", proxyPort);
        this.proxyPort = proxyPort;
    }
}
